//
//  TypeController.m
//  MyTrip
//
//  Created by zhang on 15/8/28.
//  Copyright (c) 2015年 张益. All rights reserved.
//

#import "TypeController.h"
#import "IconView.h"


@interface TypeController ()

@end

@implementation TypeController


- (void)dealloc
{
    [super dealloc];
}

- (instancetype) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)createView{
    for (int i = 0; i < 7; i++) {
        
        IconView *icon = [[[IconView alloc] initWithFrame:CGRectMake(i % 3 * (self.view.frame.size.width / 4  + (30 * OffWidth)) + (35 * OffWidth), i / 3  * (150 * OffHeight) + (100 * OffHeight), self.view.frame.size.width / 6 , 130 * OffHeight)] autorelease];
        [self.view addSubview:icon];
        [icon setTag:1 + i];
        [icon.iconLabel setFont:[UIFont systemFontOfSize:12]];
        icon.iconLabel.textAlignment = NSTextAlignmentCenter;
        [icon.iconLabel setAlpha:0.5];
        [self setValueForIconView:icon];
        icon.target = self;
        icon.action = @selector(iconAction:);
    }
}

- (void)iconAction:(IconView *)view{
    
    [self dismissViewControllerAnimated:YES completion:^{
        [self.delegate receiveTag:view.tag];
    }];
    
}



- (void)setValueForIconView:(IconView *)view{
    
    switch (view.tag) {
        case 1:
            [view.icon setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1tuijian" ofType:@"png"]]];
            [view.iconLabel setText:@"本月推荐"];
            break;
        case 2:
            [view.icon setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"remen" ofType:@"png"]]];
            [view.iconLabel setText:@"热门城市"];
            break;
        case 3:
            [view.icon setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"gangaotai" ofType:@"png"]]];
            [view.iconLabel setText:@"港澳台"];
            break;
        case 4:
            [view.icon setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"guonei" ofType:@"png"]]];
            [view.iconLabel setText:@"国内城市"];
            break;
        case 5:
            [view.icon setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ouzhou" ofType:@"png"]]];
            [view.iconLabel setText:@"欧洲城市"];
            break;
        case 6:
            [view.icon setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"meizhou" ofType:@"png"]]];
            [view.iconLabel setText:@"美洲城市"];
            break;
        case 7:
            [view.icon setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"yazhou" ofType:@"png"]]];
            [view.iconLabel setText:@"亚洲城市"];
            break;
        default:
            break;
    }
    
    
    
}




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self createView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
